package com.itboye.app.mian.activity;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.itboye.config.GlobalConfig;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.jmsfhz.R;
import com.itboye.jmsfhz.app.MainApplication;
import com.itboye.jmsfhz.app.logincontroller.LoginController;
import com.itboye.jmsfhz.app.logincontroller.LoginedState;
import com.itboye.jmsfhz.app.ui.main.MainPresenter;
import com.itboye.jmsfhz.data.model.PersonDataBean;

public class ActivityUpdateNeCheng extends BaseActivity implements Observer,OnClickListener{

	EditText edtNickName;
	String title;
	TextView anquanyanzheng;
	Button btnEdtext;
	MainPresenter presenter;
	PersonDataBean bean;
	
String uid;
	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.safe_pay;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		title = getIntent().getStringExtra("title");
		anquanyanzheng.setText(title);
		final String nickName = (String) SPUtils.get(this, null,
				SpPublicParams.NICK_NAME, "");
		edtNickName.setText(nickName);
		edtNickName.setHint("修改呢称");
		uid = SPUtils.get(ActivityUpdateNeCheng.this, null, SpPublicParams.UID, "")
				+ "";
		presenter=new MainPresenter(this);
		bean=new PersonDataBean();
	}

	public void back(View view) {
		this.finish();
	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity model = super.handlerError(data);

		if (model.getEventType() == presenter.UpdatePswByPwdFailureEvent) {
			
		}else{
			ByAlert.alert(""+model.getData());
			Intent intent2 = new Intent("titlenikname");
			sendBroadcast(intent2);
			
			finish();
		}
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btnEdtext:
			
		String name=edtNickName.getText().toString().trim();
		bean.setNickname(name);
		presenter.getNikNameUpdate(name,uid);//(bean);
		
		SPUtils.put(MainApplication.context, null, SpPublicParams.NICK_NAME,name);
		Intent intent2 = new Intent("titlenikname");
		sendBroadcast(intent2);
			break;

		default:
			break;
		}
	}
	
	

}
